package com.serviceImpl;

import java.util.List;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.entity.User;
import com.mapper.ArticleMapper;
import com.mapper.UserMapper;
import com.service.UserService;
/**
 * MingCha yang
 * @author Zhihua
 *
 */
@Service("userServiceImpl")
public class UserServiceImpl implements UserService{
	@Resource
    private UserMapper userMapper;
	@Resource
	private ArticleMapper articleMapper;
	@Override
	public User login(String un, String pwd) {
		// TODO Auto-generated method stub
		return userMapper.getUserByNameAndPass(un, pwd);
	}
	@Override
	public void addUser(User user) {
		// TODO Auto-generated method stub
		userMapper.addUser(user);
	}
	@Override
	public List<User> getUserList() {
		List<User> listUser = userMapper.listUser();
		for (User user:listUser) {
			user.setArticleCounts(articleMapper.getCountsByuserId(user.getUserId()));
		}
		return listUser;
	}
	@Override
	public User getUserById(Integer userId) {
		
		return userMapper.getUserById(userId);
	}
	
}
